package com.stu.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author MI
 * @ClassName Display.java
 * @createTime 2022年01月10日 15:30:00
 */
@Component("display")
public class Display {

    /**
     * 测试会自动注入
     */
    @Autowired
    private final Map<String, AbstractDisplay> strategyMap = new ConcurrentHashMap<>(3);

    private AbstractDisplay strategy;

    public void factory(String serviceName) {
        strategy = strategyMap.get(serviceName);
    }

    public void calcDistance() {
        System.out.println(strategyMap);
        strategy.display();
    }
}
